﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace Entity
{
    /// <summary>
    /// 项目使用的数据上下文
    /// 数据上下文可以有多个
    /// 以对应使用不同的数据库
    /// </summary>
    public class ApiDbContext:DbContext
    {
        /// <summary>
        /// 数据上下文构造函数
        /// </summary>
        /// <param name="opts">EF Core 链接数据库时使用的参数，比如链接字符串等</param>
        public ApiDbContext(DbContextOptions<ApiDbContext> opts) : base(opts)
        {

        }

        /// <summary>
        /// 作用：将类映射到数据库中
        /// 用户信息
        /// </summary>
        public DbSet<EntityUser> EntityUser { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<EntityUser>().HasData([
                new EntityUser()
                {
                    Id = Guid.NewGuid(),
                    Age = 16,
                    Email = "admin@admin.com",
                    Gender = true,
                    FirstName = "张",
                    LastName = "三",
                    PhoneNumber = "123456789",
                },
                new EntityUser()
                {
                    Id = Guid.NewGuid(),
                    Age = 21,
                    Email = "lisi@admin.com",
                    Gender = false,
                    FirstName = "李",
                    LastName = "四",
                    PhoneNumber = "987321456",
                }
            ]);
        }
    }
    

}
